package com.example.sofa_module;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.bw.ijk.widget.IjkView;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.adapter_sdk.quick.BaseQuickMoreAdapter;
import com.example.loadimg_sdk.ImgLoad;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class SofaAdapter extends BaseMultiItemQuickAdapter<SofaFeedEntity.DataBean.VideoData, BaseViewHolder> {
    public SofaAdapter() {
        addItemType(0,R.layout.item_text);
        addItemType(1,R.layout.item_pic);
        addItemType(2,R.layout.item_video);
        addChildClickViewIds(R.id.item_like);
        addChildClickViewIds(R.id.item_disslike);
        addChildClickViewIds(R.id.item_share);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, SofaFeedEntity.DataBean.VideoData item) {
        ImageView head = holder.getView(R.id.item_head);
        ImgLoad.loadCircleImg(item.author.avatar,head);
        holder.setText(R.id.item_name,item.author.name);
        holder.setText(R.id.item_intro,item.feeds_text);
        CheckBox like = holder.getView(R.id.item_like);
        CheckBox disLike = holder.getView(R.id.item_disslike);
        CheckBox comment = holder.getView(R.id.item_comment);
        CheckBox share = holder.getView(R.id.item_share);
        like.setText(item.ugc.likeCount+"");
        comment.setText(item.ugc.commentCount+"");
        share.setText(item.ugc.shareCount+"");
        if (item.ugc.hasLiked){
            like.setChecked(true);
            disLike.setChecked(false);
        }else {
            like.setChecked(false);
            disLike.setChecked(true);
        }
        switch (item.itemType){
            case 0:{
                holder.setText(R.id.item_background,item.activityText);
            }break;
            case 1:{
                ImageView background = holder.getView(R.id.item_background);
                ImgLoad.loadMatchImg(item.cover,background);
            }break;
            case 2:{
                IjkView ijkView = holder.getView(R.id.item_background);
                ijkView.setImgUrl(item.cover);
                ijkView.setPlayUrl(item.url);
            }break;
        }
    }
}
